<?php

namespace app\modules\setting\configs\cpgl;

use sookie\excel\SaveExcel;
use yii\db\ActiveRecord;
use sookie\react\handlers\UrlHandler;
use yii\helpers\Json;
use app\modules\setting\models\cpgl\QlUserTiktokProductGoods;
use sookie\bootstraps\handlers\AuthChecker;

/**
* Class TestConfig
* @package sookie\react\configs
* app\modules\setting\configs\cpgl\CplbConfig 模型的配置类
*/
class CplbConfig{

    /**
    * @return array
    * 获取搜索表单配置
    */
    public static function getSearchConfig(){
    return [
            [
                "component" => "FormInput",
                "field" => "name",
                "label" => "产品名称",
                "placeholder" => "产品名称",
                "allowClear" => true,
            ],

    ];
    }

    /**
    * @return array
    * 获取表格的操作
    */
    public static function getTableActions(){
        return  [
            [
                "actionType" => "EXPORT",
                "config" => self::getExcelHeaderMap(),
                "configUri" => UrlHandler::toAction("cpgl/cplb","export"),
                "auth" => AuthChecker::doPermissionCheck("cpgl/cplb","export"),
                "configParams" => new \ArrayObject(),
                "label" => "批量导出",
                "icon" => "export",
                "type" => "primary",
            ],
        ];
    }

    /**
    * @return array
    * 获取表格行的操作
    * [] 表示要id, ["*"] 表示要一行记录,参数名record, ["id"] 指定需要的参数 ， selected_ids 表示需要所有选择的id
    * configParamsField 规定请求的时候带上数据行中的那些参数，只需要字段名
    */
    public static function getTableRowAction(){
        return [
            [

                "actionType" => "CONFIRM",
                "method" => "post",
                "config" => [
                    "title" => "下架",
                    "content" => "产品在邮件系统中下架，邮件中不再发送该产品！",
                ],
                "configUri" => UrlHandler::toAction("cpgl/cplb","down"),
                "auth" => AuthChecker::doPermissionCheck("cpgl/cplb","update"),
                "configParamsField" => ["id"],
                "label" => "下架",
            ],
            [

                "actionType" => "CONFIRM",
                "method" => "post",
                "config" => [
                    "title" => "撤销下架",
                    "content" => "撤销下架操作，邮件中将会发送该产品！",
                ],
                "configUri" => UrlHandler::toAction("cpgl/cplb","on"),
                "auth" => AuthChecker::doPermissionCheck("cpgl/cplb","update"),
                "configParamsField" => ["id"],
                "label" => "撤销下架",
            ],
        ];
    }

    /**
    * @return array
    * 获取表格配置
    */
    public static function getTableConfig(){
        return [
            "rowKey" => "id",
            "columns" => [
                [
                    "title" => "产品名称",
                    "dataIndex" => "name",
                    "sorter" => true,
                    "key" => "name",
                    "format" => "raw",
                ],
                [
                    "title" => "最低价格",
                    "dataIndex" => "min_price",
                    "sorter" => true,
                    "key" => "min_price",
                    "format" => "text",
                ],
                [
                    "title" => "最高价格",
                    "dataIndex" => "max_price",
                    "sorter" => true,
                    "key" => "max_price",
                    "format" => "text",
                ],
                [
                    "title" => "达人佣金比例",
                    "dataIndex" => "creator_commission_percent",
                    "sorter" => true,
                    "key" => "creator_commission_percent",
                    "format" => "text",
                ],
                [
                    "title" => "商家佣金比例",
                    "dataIndex" => "seller_commission_percent",
                    "sorter" => true,
                    "key" => "seller_commission_percent",
                    "format" => "text",
                ],
                [
                    "title" => "星级",
                    "dataIndex" => "product_rating",
                    "sorter" => true,
                    "key" => "product_rating",
                    "format" => "text",
                ],
                [
                    "title" => "评论",
                    "dataIndex" => "product_review_count",
                    "sorter" => true,
                    "key" => "product_review_count",
                    "format" => "text",
                ],
                [
                    "title" => "出售数",
                    "dataIndex" => "product_sales",
                    "sorter" => true,
                    "key" => "product_sales",
                    "format" => "text",
                ],
                [
                    "title" => "样品数量",
                    "dataIndex" => "sample_quota",
                    "sorter" => true,
                    "key" => "sample_quota",
                    "format" => "text",
                ],
                [
                    "title" => "模块",
                    "dataIndex" => "type",
                    "sorter" => true,
                    "key" => "type",
                    "format" => "text",
                ],
                [
                    "title" => "状态",
                    "dataIndex" => "ban",
                    "sorter" => true,
                    "key" => "ban",
                    "format" => "raw",
                ],
            ],
            "actions" => self::getTableRowAction()
        ];
    }

    /**
    * 首页配置
    */
    public static function configIndex(){
        return [
            //搜索表单配置
            "searchConfig" => self::getSearchConfig(),
            // 操作配置 configParams 规定请求的时候带上那些参数
            "actionDivConfig" => self::getTableActions(),
            //表格配置
            "tableConfig" => self::getTableConfig(),
        ];
    }





    /**
    * 获取Excel表格的表头-字段映射关系
    */
    public static function getExcelHeaderMap(){
        return [
            "fileName" => "product",
            "format" => SaveExcel::XLXS,
            "config" => [
                "产品名称" => "name",
                "价格" => "price",
                "最低价格" => "min_price",
                "最高价格" => "max_price",
                "达人佣金比例" => "creator_commission_percent",
                "商家佣金比例" => "seller_commission_percent",
                "星级" => "product_rating",
                "评论" => "product_review_count",
                "出售数" => "product_sales",
                "店铺编号" => "shop_code",
                "样品数量" => "sample_quota",
                "图片" => "img",
                "分享链接" => "link",
                "产品链接" => "product_link",
                "创建时间" => "created_at",
            ]
        ];
    }

}

